<?php
namespace app\np\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use think\Db;
use think\Config;
class Code extends Command
{
    protected function configure()
    {
        $this->setName('code')->setDescription('Code every Minutes ');
    }
    protected function execute(Input $input, Output $output)
    {
                set_time_limit(0);
                header("Connection: Keep-Alive");
        header("Proxy-Connection: Keep-Alive");
        $CodeList = new \app\np\model\Shares();
        $MarkPriceList = new \app\admin\model\MarkPrice();
        $page = 67;
        while(1){
        $resultCode = $CodeList->limit($page*25,25)->select();
        $page++;
        $resultJSon = json_decode(json_encode($resultCode),true);
        if(count($resultJSon)==0){
            error_log("参数xxxxxxxxxx...".PHP_EOL, 3, "/home/wwwlogs/result_break.log");
            break;
        }
        $auto = new \auto\Qi();
        foreach($resultJSon as $kr=>$vr){
            $result = $auto->order2($vr['code']);
            if(empty($result))
            {
                error_log(json_encode($result).PHP_EOL, 3, "/home/wwwlogs/result_log.log");

            }else{
                if(isset($result['status'])){
                    while(  isset($result['status'])&&$result['status']==99 ){
                        $result = $auto->order2($vr['code']);
                        sleep(15*60);
                    }
                }

                $data = [
                    "name"=>$vr['name'],
                    "code"=>$vr['code'],
                    "attr"=>$vr['attribute'],
                ];
                foreach($result as $k=>$v){
                    if($vr['attribute']=="沪A"){
                        $vr['attribute'] = "SH";
                    }
                    if($vr['attribute']=="深A"){
                        $vr['attribute'] = "SZ";
                    }
                    $data['attr'] = $vr['attribute'] ;
                    if($v['Cycle']=="5d"){ //5天
                        $data['fday'] = $v['Offer_price'];
                    }elseif($v['Cycle']=="10d"){
                        $data['tday'] = $v['Offer_price'];
                    }elseif($v['Cycle']=="1m"){
                        $data['one'] = $v['Offer_price'];
                    }elseif($v['Cycle']=="2m"){
                        $data['two'] = $v['Offer_price'];
                    }elseif($v['Cycle']=="3m"){
                        $data['three'] = $v['Offer_price'];
                    }elseif($v['Cycle']=="6m"){
                        $data['six'] = $v['Offer_price'];
                    }

                }

            }





           $MarkPriceList->saveAll([$data]);

        }





        }





    }
}